package com.bilibili.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bilibili.entity.Danmaku;
import com.bilibili.service.SelectDanmuService;
import com.bilibili.service.impl.SelectDanmuServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;

@WebServlet("/selectDanmu.do")
public class SelectDanmuServlet extends HttpServlet {
	
	private SelectDanmuService sds=new SelectDanmuServiceImpl();
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("application/json;charset=utf-8");
		ObjectMapper om=new ObjectMapper();
		String videoId=request.getParameter("videoId");
		int videoid=Integer.parseInt(videoId);
		List<Danmaku> dm=sds.getDanmu(videoid);
		String dmStr=om.writeValueAsString(dm);
		response.getWriter().write(dmStr);
	}

}
